{% extends 'scms/base.html' %}
{% block link %}
{#    <meta id="refresh" http-equiv="refresh" content="5">#}
    <link href="/static/scms/dist/css/pcmanager.css" rel="stylesheet" type="text/css">
    <link href="/static/scms/vendor/bootstrap/css/bootstrapValidator.min.css" rel="stylesheet">
{% endblock %}
{% block body %}
    <div class="wrapper wrapper-content animated fadeInRight">
			    <div class="row">
			        <div class="col-lg-12">
			            <div class="ibox float-e-margins" id="all">
			                <div class="ibox-title shezhiye">
			                    <h3> 任务列表页</h3>
			                    <h5> *显示当前任务执行情况</h5>
			                </div>
							<div class="col-lg-12">
			                <div class="ibox-content">
                                    <!--添加机器弹窗-->
						            <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
									  <div class="modal-dialog">
									    <div class="modal-content">
									      <div class="modal-header">
									        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
									        <h4 class="modal-title" id="myModalLabel">任务日志</h4>
									      </div>
									      <div class="modal-body" id="xianshi">
                                            <pre id="logs"></pre>
									      </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                            </div>
                                        </div>
									</div>
									</div>
						            <!--弹窗结束-->
			                        <div id="export"></div>
			                        <table class=" table table-striped table-bordered table-hover " id="editable" name="editable">
			                            <thead>
			                                <tr>
			                                    <th class="text-center">序号</th>
			                                    <th class="text-center">任务名</th>
			                                    <th class="text-center" name="ip">被操作IP或组名</th>
			                                    <th class="text-center">配置文件名</th>
			                                    <th class="text-center">操作日志</th>
			                                    <th class="text-center">操作结果</th>
			                                </tr>
			                            </thead>
			                            <tbody>
											{% for topic in topics %}
												<tr class="gradeX">
													<td class="text-center">{{ topic.id }}</td>
													<td class="text-center">{{ topic.task_name }}</td>
													<td class="text-center">{{ topic.task_Operated }}</td>
													<td class="text-center">{{ topic.config_name }}</td>
{#													<td class="text-center">{{topic.task_log}}</td>#}
                                                    <span style="display: none" id="logs{{ topic.id }}">{{topic.task_log}}</span>
													<td class="text-center"><a class="stopfresh" href="#"  onclick="logshow(this,{{ topic.id }});">查看日志</a></td>
													<td class="text-center">
                                                        {% if topic.task_result == '1'  %}
                                                            <span class="badge badge-success">成功</span>
                                                            {% elif topic.task_result == '2' %}
                                                            <span class="badge badge-danger">失败</span>
                                                            {% elif topic.task_result == '3' %}
                                                            <span class="badge badge-primary">进行中</span>
                                                        {% endif %}

                                                    </td>
												</tr>
											{% endfor %}
			                            </tbody>
			                        </table>
			                </div>
			                </div>
			            </div>
			        </div>
			    </div>

			<div id="fenye" class="pagination">
			    <nav>
					<ul class="pagination">
					{% if topics.has_previous %}
						<li><a href="?page={{ topics.previous_page_number }}">&laquo;</a></li>
						{% else %}
						<li class="disabled"><a href="#">&laquo;</a></li>
					  {% endif %}
					  {% for page_number in topics.paginator.page_range %}
						{% ifequal page_number  topics.number %}
							<li class="active"><a>{{ page_number }}</a></li>
						{% else %}
							<li><a href="?page={{ page_number }}">{{ page_number }}</a></li>
						{% endifequal %}
					  {% endfor %}
					{% if topics.has_next %}
						<li><a href="?page={{ topics.next_page_number }}">&raquo;</a></li>
						{% else %}
						<li class="disabled"><a href="#">&raquo;</a></li>
					{% endif %}
					</ul>
				</nav>
			</div>
        </div>
{% endblock %}

{% block javascript %}
    <script src="/static/scms/vendor/bootstrap/js/bootstrapValidator.min.js"></script>
		<script src="/static/scms/dist/js/jquery.cookie.js"></script>
		<script>
			var csrftoken = $.cookie('csrftoken');
        function csrfSafeMethod(method) {
            // these HTTP methods do not require CSRF protection
            return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
        }
        $.ajaxSetup({
            beforeSend: function(xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
                }
            }
        });
		</script>
    <script>
    function logshow(doc,id) {
        var obj = setTimeout('myrefresh()',6000);
                $('#logs').text($("#logs"+id).text())
				$('#myModal2').modal({show:true});
                clearInterval(obj);
        };
    </script>
    <script>
    function myrefresh(){
        window.location.reload();
    };
    $(function(){
        var obj = setTimeout('myrefresh()',6000); // 每6秒刷新一次页面
        $("a.stopfresh").click(function(){
            clearInterval(obj); // 点击即停止刷新
        });
    });
    $(function () { $('#myModal2').on('hide.bs.modal', function () {
      setTimeout('myrefresh()',1000);})
    });
    </script>
{% endblock %}